package com.token.zhuishushenqi.community.entity;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;
import org.json.JSONObject;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by pengjianhuan on 2016/11/7 0007.
 */
//书评区的数据解析
public class CommentJosn {

    private String _id;
    private String title;
    private BookBean book;
    private HelpfulBean helpful;
    private int likeCount;
    private String state;
    private String updated;
    private String created;

    public static CommentJosn objectFromData(String str) {

        return new Gson().fromJson(str, CommentJosn.class);
    }

    public static CommentJosn objectFromData(String str, String key) {

        try {
            JSONObject jsonObject = new JSONObject(str);

            return new Gson().fromJson(jsonObject.getString(str), CommentJosn.class);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }

    public static List<CommentJosn> arrayCommentJosnFromData(String str) {

        Type listType = new TypeToken<ArrayList<CommentJosn>>() {
        }.getType();

        return new Gson().fromJson(str, listType);
    }

    public static List<CommentJosn> arrayCommentJosnFromData(String str, String key) {

        try {
            JSONObject jsonObject = new JSONObject(str);
            Type listType = new TypeToken<ArrayList<CommentJosn>>() {
            }.getType();

            return new Gson().fromJson(jsonObject.getString(str), listType);

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return new ArrayList();


    }

    public String get_id() {
        return _id;
    }

    public void set_id(String _id) {
        this._id = _id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public BookBean getBook() {
        return book;
    }

    public void setBook(BookBean book) {
        this.book = book;
    }

    public HelpfulBean getHelpful() {
        return helpful;
    }

    public void setHelpful(HelpfulBean helpful) {
        this.helpful = helpful;
    }

    public int getLikeCount() {
        return likeCount;
    }

    public void setLikeCount(int likeCount) {
        this.likeCount = likeCount;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getUpdated() {
        return updated;
    }

    public void setUpdated(String updated) {
        this.updated = updated;
    }

    public String getCreated() {
        return created;
    }

    public void setCreated(String created) {
        this.created = created;
    }

    public static class BookBean {
        private String _id;
        private String cover;
        private String title;
        private String site;
        private String type;

        public static BookBean objectFromData(String str) {

            return new Gson().fromJson(str, BookBean.class);
        }

        public static BookBean objectFromData(String str, String key) {

            try {
                JSONObject jsonObject = new JSONObject(str);

                return new Gson().fromJson(jsonObject.getString(str), BookBean.class);
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

        public static List<BookBean> arrayBookBeanFromData(String str) {

            Type listType = new TypeToken<ArrayList<BookBean>>() {
            }.getType();

            return new Gson().fromJson(str, listType);
        }

        public static List<BookBean> arrayBookBeanFromData(String str, String key) {

            try {
                JSONObject jsonObject = new JSONObject(str);
                Type listType = new TypeToken<ArrayList<BookBean>>() {
                }.getType();

                return new Gson().fromJson(jsonObject.getString(str), listType);

            } catch (JSONException e) {
                e.printStackTrace();
            }

            return new ArrayList();


        }

        public String get_id() {
            return _id;
        }

        public void set_id(String _id) {
            this._id = _id;
        }

        public String getCover() {
            return cover;
        }

        public void setCover(String cover) {
            this.cover = cover;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getSite() {
            return site;
        }

        public void setSite(String site) {
            this.site = site;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }
    }

    public static class HelpfulBean {
        private int total;
        private int yes;
        private int no;

        public static HelpfulBean objectFromData(String str) {

            return new Gson().fromJson(str, HelpfulBean.class);
        }

        public static HelpfulBean objectFromData(String str, String key) {

            try {
                JSONObject jsonObject = new JSONObject(str);

                return new Gson().fromJson(jsonObject.getString(str), HelpfulBean.class);
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

        public static List<HelpfulBean> arrayHelpfulBeanFromData(String str) {

            Type listType = new TypeToken<ArrayList<HelpfulBean>>() {
            }.getType();

            return new Gson().fromJson(str, listType);
        }

        public static List<HelpfulBean> arrayHelpfulBeanFromData(String str, String key) {

            try {
                JSONObject jsonObject = new JSONObject(str);
                Type listType = new TypeToken<ArrayList<HelpfulBean>>() {
                }.getType();

                return new Gson().fromJson(jsonObject.getString(str), listType);

            } catch (JSONException e) {
                e.printStackTrace();
            }

            return new ArrayList();


        }

        public int getTotal() {
            return total;
        }

        public void setTotal(int total) {
            this.total = total;
        }

        public int getYes() {
            return yes;
        }

        public void setYes(int yes) {
            this.yes = yes;
        }

        public int getNo() {
            return no;
        }

        public void setNo(int no) {
            this.no = no;
        }
    }
}
